﻿Imports System.Data
Public Class uc_ItemDetail


    Private Sub uc_ItemDetail_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.BackColor = Color.Orchid

    End Sub

    Private Sub txt_Item_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.BackColor = Color.Orchid

    End Sub

    Private Sub txt_Item_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.BackColor = System.Drawing.SystemColors.Control
    End Sub

    Private Sub txt_Price_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_Price.GotFocus, btn_Item.GotFocus
        Me.BackColor = Color.Orchid
    End Sub

    Private Sub txt_Price_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_Price.LostFocus, btn_Item.LostFocus
        Me.BackColor = System.Drawing.SystemColors.Control
    End Sub

    Private Sub btn_Item_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Item.Click
        Dim frm As New popup_Items
        If frm.ShowDialog = DialogResult.OK Then
            btn_Item.Tag = frm.dg_Items.Item(frm.dg_Items.CurrentRowIndex, 0) 'only code
            btn_Item.Text = frm.dg_Items.Item(frm.dg_Items.CurrentRowIndex, 0) + " - " + frm.dg_Items.Item(frm.dg_Items.CurrentRowIndex, 1)

        End If
    End Sub

    Private Sub uc_ItemDetail_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Me.BackColor = Color.Orchid
    End Sub

    Private Sub uc_ItemDetail_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LostFocus
        Me.BackColor = System.Drawing.SystemColors.Control
    End Sub

    Private Sub pb_Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub fillPrice()
        If txt_Qty.Text <> "" Then
            uc_NumPad.Visible = False
            Cursor.Current = Cursors.WaitCursor
            Dim qty As Double = Double.Parse(txt_Qty.Text)
            Dim wsDefault As New WebRefGetDefault.GetDefault
            Dim tb_Detail As DataTable = wsDefault.GetDefaultLineInfo(PublicVariables.cur_UserID, PublicVariables.cur_CardCode, btn_Item.Tag.ToString(), qty, DateTime.Now).Tables(0)
            If tb_Detail.Rows.Count > 0 Then
                txt_Price.Text = tb_Detail(0)("PriceAfDi").ToString()
                Dim price As Double = Double.Parse(txt_Price.Text)
                Dim total As Double = qty * price
                txt_Total.Text = total
                'RaiseEvent FinishUpdateItem(Me, e)
            End If
            Cursor.Current = Cursors.Default
        Else
            MessageBox.Show("Input qty please.")
        End If
    End Sub

    'Public Custom Event FinishUpdateItem As EventHandler
    '    AddHandler(ByVal value As EventHandler)
    '        AddHandler pb_Update.Click, value
    '    End AddHandler

    '    RemoveHandler(ByVal value As EventHandler)

    '    End RemoveHandler

    '    RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)

    '    End RaiseEvent
    'End Event

    Private Sub txt_Qty_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_Qty.GotFocus
        If btn_Item.Text <> "" Then
            uc_NumPad.Visible = True
        End If

    End Sub


    Private Sub uc_NumPad_NumberButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uc_NumPad.NumberButtonClick
        txt_Qty.Text = uc_NumPad.strNum
    End Sub

    Private Sub uc_NumPad_ClearButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uc_NumPad.ClearButtonClick
        txt_Qty.Text = ""
    End Sub

    Private Sub uc_NumPad_OkButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uc_NumPad.OkButtonClick
        uc_NumPad.Visible = False
        fillPrice()
    End Sub

    Private Sub uc_ItemDetail_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        txt_Price.TextAlign = HorizontalAlignment.Right
        txt_Qty.TextAlign = HorizontalAlignment.Right
        txt_Total.TextAlign = HorizontalAlignment.Right

    End Sub
End Class
